Conversation
- Backend: Dynamic LaTeX header/footer generation with columns/font_size/margins support - Backend: generate_sheet endpoint now accepts layout options from request - Frontend: LayoutOptions component with column and text size dropdowns - Frontend: Compile button regenerates LaTeX with current layout options - All 26 backend tests pass
Add \raggedcolumns after \begin{multicols} to prevent content bleeding
between columns when using 3-column layout.
- Add spacing dropdown (tiny/small/medium/large) controlling vertical spacing - Reduce section/subsection header sizes via titleformat - Center editor layout with 42.5%/42.5% pane widths and 2.5% margins
… adjustbox for formula auto-scaling
There was a problem hiding this comment.
Pull request overview
This PR enhances the cheat sheet generator by adding user-configurable layout options that flow from the frontend into backend LaTeX generation, plus UX improvements (line-numbered editor) and persistence/versioning via localStorage.
Changes:
- Backend: generate LaTeX dynamically based on layout options (columns/font size/margins/spacing) and auto-scale formulas to column width.
- Frontend: add layout controls, line-numbered LaTeX editor, version navigation, and persist selections/content across reloads.
- Styling/docs: broaden layout to full width and update README + UI styling for the new workflow.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents new preview/editor behavior and persistence/version history. |
| frontend/src/index.css | Removes centered/max-width root constraints to support full-width layout. |
| frontend/src/hooks/latex.js | Adds layout state, auto-save, compile/regenerate flow, and version history. |
| frontend/src/hooks/formulas.js | Persists formula selections and ordering in localStorage. |
| frontend/src/components/CreateCheatSheet.jsx | Adds layout controls UI and a line-numbered LaTeX editor with history controls. |
| frontend/src/App.jsx | Initializes/restores cheat sheet state from localStorage and saves progress. |
| frontend/src/App.css | Large styling refresh for panels/editor/controls and responsive behavior. |
| backend/api/views.py | Extends /api/generate-sheet/ to accept layout options and pass them through to LaTeX generation. |
| backend/api/latex_utils.py | Introduces dynamic LaTeX header/footer generation + spacing/font sizing + equation auto-scaling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| columns = request.data.get("columns", 2) | ||
| font_size = request.data.get("font_size", "10pt") | ||
| margins = request.data.get("margins", "0.25in") | ||
| spacing = request.data.get("spacing", "large") |
There was a problem hiding this comment.
font_size, margins, and spacing are passed straight into LaTeX generation (e.g., \documentclass[...] and geometry options). These should be validated/whitelisted to known-safe values to avoid LaTeX injection or unexpected compilation behavior when the API is called directly (not just via the UI).
| selected = request.data.get("formulas", []) | ||
| columns = request.data.get("columns", 2) | ||
| font_size = request.data.get("font_size", "10pt") | ||
| margins = request.data.get("margins", "0.25in") | ||
| spacing = request.data.get("spacing", "large") |
There was a problem hiding this comment.
The endpoint now supports additional layout parameters (columns, font_size, margins, spacing), but the existing test suite likely only covers the legacy {formulas: [...]} payload. Please add/extend API tests to exercise these new parameters (including validation) and assert the generated LaTeX reflects them (e.g., \begin{multicols}{3} / geometry margin).
| columns = request.data.get("columns", 2) | ||
| font_size = request.data.get("font_size", "10pt") | ||
| margins = request.data.get("margins", "0.25in") | ||
| spacing = request.data.get("spacing", "large") |
There was a problem hiding this comment.
font_size, margins, and spacing are passed straight into LaTeX generation (e.g., \documentclass[...] and geometry options). These should be validated/whitelisted to known-safe values to avoid LaTeX injection or unexpected compilation behavior when the API is called directly (not just via the UI).
| useEffect(() => { | ||
| if (initialData) { | ||
| if (initialLoaded.current) return; | ||
|
|
||
| const saved = loadLatexStorage(); | ||
| if (saved && !initialData?.content) { | ||
| initialLoaded.current = true; | ||
| setTitle(saved.title ?? ''); | ||
| setContent(saved.content ?? ''); | ||
| setColumns(saved.columns ?? 2); | ||
| setFontSize(saved.fontSize ?? '10pt'); | ||
| setSpacing(saved.spacing ?? 'large'); | ||
| } else if (initialData) { | ||
| initialLoaded.current = true; |
There was a problem hiding this comment.
The initial-load precedence can unexpectedly ignore initialData when initialData.content is an empty string (because !initialData?.content is true). That means persisted cheatSheetLatex can override a deliberately empty sheet passed in by the parent. Consider using an explicit check like initialData?.content == null (null/undefined only) to decide when storage should win.
| useEffect(() => { | ||
| saveLatexStorage({ title, content, columns, fontSize, spacing }); | ||
| }, [title, content, columns, fontSize, spacing]); |
There was a problem hiding this comment.
Auto-saving to localStorage on every change to content means a synchronous localStorage.setItem on every keystroke, which can block the UI for larger documents. Consider debouncing/throttling this effect so writes happen after the user pauses typing.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
| const data = await response.json(); | ||
| contentToCompile = data.tex_code; | ||
| setContent(data.tex_code); | ||
| if (content) saveToHistory(data.tex_code); | ||
| } |
There was a problem hiding this comment.
handlePreview references saveToHistory, but the callback’s dependency array does not include it. This can lead to stale history state (and typically violates the exhaustive-deps lint rule). Add the missing dependencies or refactor to avoid capturing changing values.
| body: JSON.stringify({ | ||
| formulas: selectedList, | ||
| columns: columns, | ||
| font_size: fontSize, | ||
| spacing: spacing, | ||
| margins: '0.25in' | ||
| }), |
There was a problem hiding this comment.
margins is hard-coded to '0.25in' in the request payloads, so the UI currently can’t actually vary margins despite the PR description/README claiming adjustable margins. Either add a margins control and pass the selected value through, or update the docs/description to match the implemented behavior.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@bdtran2002 it looks good, but im not noticing much from the "spacing" option, is it working the way you want it to? |
This pull request introduces several significant enhancements to the cheat sheet generator, focusing on customizable LaTeX output, improved frontend usability, and persistent user progress. The backend now supports user-selected layout options—such as column count, font size, and spacing—which are reflected in the dynamically generated LaTeX. The frontend adds intuitive controls for these options, a line-numbered LaTeX editor, auto-save and version history features, and persists formula selections and layouts across sessions.
Backend: LaTeX Generation and API Improvements
columns,font_size,margins,spacing) when generating cheat sheets, ensuring the output matches user preferences [1] [2].Frontend: User Experience and Layout Controls
LayoutOptionscomponent, allowing users to select column count, text size, and spacing, with these choices sent to the backend for LaTeX generation [1] [2].Persistence and Versioning
localStorage, restoring state on reload [1] [2].Other Usability Enhancements
Code organization
latex_utils.pyto the backend API for better separation of LaTeX generation logic.These changes collectively make the cheat sheet generator more flexible, robust, and user-friendly, with a focus on customization and persistent user workflows.